import 'package:flutter/material.dart';

import '../Home/index.dart';
import '../Mine/index.dart';

class TabsPage extends StatefulWidget {
  const TabsPage({Key? key}) : super(key: key);

  @override
  _TabsPageState createState() => _TabsPageState();
}

class _TabsPageState extends State<TabsPage> {
  int _currentIndex = 0;

  List _tabList = [
    {
      'label': '首页',
      'icon': 'assets/tabs/home_default.png',
      'activeIcon': 'assets/tabs/home_active.png',
    },
    {
      'label': '我的',
      'icon': 'assets/tabs/my_default.png',
      'activeIcon': 'assets/tabs/my_active.png',
    },
  ];
//底部tab栏的列表
  List<BottomNavigationBarItem> getTabsBar() {
    List<BottomNavigationBarItem> tabsList = [];

    for (var i = 0; i < _tabList.length; i++) {
      tabsList.add(BottomNavigationBarItem(
        icon: Image.asset(
          _tabList[i]['icon'],
          height: 30,
          width: 30,
        ),
        activeIcon: Image.asset(
          _tabList[i]['activeIcon'],
          height: 30,
          width: 30,
        ),
        label: _tabList[i]['label'],
      ));
    }

    return tabsList;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
          child: IndexedStack(
        index: _currentIndex,
        children: const [
          HomeView(),
          MineView(),
        ],
      )),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _currentIndex,
        onTap: (index) {
          setState(() {
            _currentIndex = index;
          });
        },
        items: getTabsBar(),
      ),
    );
  }
}
